package com.test.service;

import com.seata.api.BusinessService;
import com.seata.api.OrderService;
import com.seata.api.StorageService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class BusinessServiceImpl implements BusinessService {

    @DubboReference
    StorageService storageService;
    @DubboReference
    OrderService orderService;

    @GlobalTransactional // seata分布式事务注解
    @Override
    public void purchase(String userId, String commodityCode, int orderCount) {

        // 扣减库存
        storageService.deduct(commodityCode, orderCount);
        // 创建订单
        orderService.create(userId, commodityCode, orderCount);

    }
}